﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Remember
{
    public class AddNoteViewModel : ObjectBase
    {
        private MainWindowViewModel mainModel;

        public Commands Commands { get; private set; }
        public Note Note;

        public AddNoteViewModel(MainWindowViewModel mainModel)
        {
            this.mainModel = mainModel;
            Commands = mainModel.Commands;
            Note = new Note();
        }

        public string Title
        {
            get { return Note.Title; }
            set
            {
                if (Note.Title == value)
                    return;
                Note.Title = value;
                OnPropertyChanged("Title");
            }
        }

        public string Text
        {
            get { return Note.Text; }
            set
            {
                if (Note.Text == value)
                    return;
                Note.Text = value;
                OnPropertyChanged("Text");
            }
        }

        public DateTime ExpiryDate
        {
            get { return Note.ExpiryDate.Value; }
            set
            {
                //DateTime date = DateTime.ParseExact(
                //value.ToString("yyyy-MM-ddTHH:mm:ss", CultureInfo.CurrentCulture),
                //"yyyy-MM-ddTHH:mm:ss",
                //CultureInfo.CurrentCulture);
                string d = value.Year.ToString() + "-" + value.Month.ToString() + "-" + value.Day.ToString();
                Date date = new Date(d);
                Debug.WriteLine("Value: " + d);
                if (Note.ExpiryDate.Value == date.Value)
                    return;
                Note.ExpiryDate.Value = date.Value;
                OnPropertyChanged("ExpiryDate");
            }
        }
    }
}
